package tosp.search;

import org.apache.log4j.Logger;

import tosp.HistoryMachine;
import tosp.JobSequence;
import tosp.job.Job;


public class ForeignSwitchSearch extends LocalSearchAdapter {

	static Logger log = Logger.getLogger(ForeignSwitchSearch.class);
	
	public ForeignSwitchSearch(HistoryMachine m) {
		super(m);
	}

	@Override
	public int getNeighborSize(JobSequence s) {
		return s.getNumberOfJobs()*s.getNumberOfJobs()-1;
	}

	@Override
	public JobSequence getNeighbor(JobSequence js,int i) {
		Job[] work=js.getJobsClone();
		if (i>=getNeighborSize(js)) return null;
		int from=i/js.getNumberOfJobs();
		int to=i%js.getNumberOfJobs();
		Job temp=work[to];
		work[to]=work[from];
		work[from]=temp;
		
		JobSequence newjs = new JobSequence(work,true);
		log.trace("Generated new Neighbor: "+newjs.getSeqAsString());
		
		return newjs;
	}

	@Override
	public JobSequence[] getNeighbors(JobSequence j) {
		return null;
	}
	
	/* 
	@Override
	public JobSequence[] getNeighbors(JobSequence js) {
		Vector<JobSequence> twoset = new Vector<JobSequence>();
		for (int index = 0; index < js.getNumberOfJobs(); index++) {
			for (int i = index+2; i < js.getNumberOfJobs(); i++) {
				Vector<Job> work = new Vector<Job>();
				for (int j = 0; j < js.getNumberOfJobs(); j++) {
					if (j == i) {
						work.add(js.getJob(index));
					} else if (j == index) {
						work.add(js.getJob(i));
					} else
						work.add(js.getJob(j));
				}
				twoset.add(new JobSequence(work));
			}
		}
		
		twoset.trimToSize();
		return twoset.toArray(new JobSequence[twoset.size()]);
	
	}
	*/
}
